﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.Web.Admin.ProcureManage
{
    public partial class InvoiceResolved : BasePage
    {
        public InvoiceResolved()
        {
            this.ModuleNo = Model.Enum.Module.发票管理.ToString();
        }

        IBLL_Purchase ip = Factory.BLL_Purchase();
        protected void Page_Load(object sender, EventArgs e)
        {
            SetBind();
        }

        /// <summary>
        /// 绑定发票信息
        /// </summary>
        private void SetBind()
        {
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            //构造查询实体
            Model.Query.Invoice queryModel = new Model.Query.Invoice();
            queryModel.Append = "AuditStatus <> 0";
            queryModel.SortFields = "InvoiceTime DESC";
            //加入地区过滤条件，管理机构只能管理本地区下的采购单
            queryModel.AreaID = CurrentAccount.GetUser().Org.Area.AreaID;

            IList<Model.View.Invoice> invoiceList = ip.GetInvoiceByWhere(queryModel, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwInvoice.DataSource = invoiceList;
            gvwInvoice.DataBind();
        }

        /// <summary>
        /// 绑定发票的状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwInvoice_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal ltr = e.Row.FindControl("ltrStatus") as Literal;
                if (ltr.Text == "0")
                {
                    ltr.Text = "未审核";
                }
                else if (ltr.Text == "1")
                {
                    ltr.Text = "已通过";
                }
                else if (ltr.Text == "2")
                {
                    ltr.Text = "未通过";
                }
            }
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            SetBind();
        }
    }
}
